#include <qua/error.h>
#include <qua/text.h>
#include <locale>

namespace qua
{
    using std::locale;

    class error::data
    {
    public:
        data()
    		: m_line() {
        }

        data( text const& error_message, text const& file_name, int line_no )
            : m_message( error_message ), m_file(file_name), m_line(line_no) {
        }

        text const& message() const {
            return m_message;
        }

        text const& in_file() const {
            return m_file;
        }

        int at_line() const {
            return m_line;
        }

    private:
        text m_message;
        text m_file;
        int  m_line;
    };

    const locale global_locale;

    error::error() throw()
    {
    }

    error::error( text const& message, const char* file, int line ) throw()
        : m_data( new data( message, text( file, global_locale.name() ), line ) )
    {
    }

    const char* error::what() const throw()
    {
        return m_data->message().to_encoding( global_locale.name() );
    }

    text const& error::message() const throw()
    {
        return m_data->message();
    }

    text const& error::in_file() const throw()
    {
        return m_data->in_file();
    }

    int error::at_line() const throw()
    {
        return m_data->at_line();
    }
}
